package graphs

import (
	"power/core/dao/graphdao"
	"power/core/dao/table"
	"power/core/localwrap"
	"power/core/service/graph"

	"github.com/RocksonZeta/wrap/utils/cutil"
)

type GraphElementProtoClasss struct{}

func (s GraphElementProtoClasss) Query(param graphdao.GraphElementProtoClasssQueryParam) ([]table.GraphElementProtoClass, int64) {
	ds := localwrap.GetRedisedMysql()
	defer ds.Close()
	return graphdao.GraphElementProtoClasss{RedisedMysql: ds}.Query(param)
}
func (s GraphElementProtoClasss) Get(id int) table.GraphElementProtoClass {
	ds := localwrap.GetRedisedMysql()
	defer ds.Close()
	return graphdao.GraphElementProtoClasss{RedisedMysql: ds}.Get(id)
}

// type GraphElementProtoClass struct {
// 	table.GraphElementProtoClass
// 	Protos []graph.GraphElementProto
// }

func (s GraphElementProtoClasss) List(uid int) []graph.GraphElementProtoClass {
	ds := localwrap.GetRedisedMysql()
	defer ds.Close()
	cs := graphdao.GraphElementProtoClasss{RedisedMysql: ds}.ListByUid(uid)
	r := make([]graph.GraphElementProtoClass, len(cs))
	classIds := cutil.ColInt(cs, "Id")
	allProtos := graphdao.GraphElementProtos{RedisedMysql: ds}.ListByClassIds_(classIds)
	var allProtosClassed map[int][]graph.GraphElementProto
	cutil.Group(allProtos, &allProtosClassed, "ClassId")
	for i, v := range cs {
		r[i].GraphElementProtoClass = v
		r[i].Protos = allProtosClassed[v.Id]
	}
	return r
}
func (s GraphElementProtoClasss) Add(param graphdao.GraphElementProtoClasssAddParam) table.GraphElementProtoClass {
	ds := localwrap.GetRedisedMysql()
	defer ds.Close()
	return graphdao.GraphElementProtoClasss{RedisedMysql: ds}.Add(param)
}
func (s GraphElementProtoClasss) Delete(id int) {
	ds := localwrap.GetRedisedMysql()
	defer ds.Close()
	graphdao.GraphElementProtoClasss{RedisedMysql: ds}.Delete(id)
}
func (s GraphElementProtoClasss) Update(param graphdao.GraphElementProtoClasssUpdateParam) {
	ds := localwrap.GetRedisedMysql()
	defer ds.Close()
	graphdao.GraphElementProtoClasss{RedisedMysql: ds}.Update(param)
}
